
#include "BitDefine.h"
#include "SignalDefine.h"
#include "BSP.h"
#include "Driver.h"
#include "DeviceLight.h"

extern void Env_SetWG26(void);
extern void Env_Init(void);

static uint32_t signalState;

void SignalService_Init(void){
	signalState = 0;
}

int SignalService_Serve(void){
	uint32_t sig = BSP_Signal_Get();
	//线控LED
	if(sig & Bit(Sig_LED)){
		//线控LED触发，复位DeviceLight，设置为触发状态
		DeviceLight_FlashAsync(0, 1, 100, Color_Green, 100, 0);
	}
	else
	if(signalState & Bit(Sig_LED)){
		Light_Permanent(0);
	}
	//侵入或线控蜂鸣器
	if((sig & Bit(Sig_BUZ)) || (sig & Bit(Sig_TAMP))){
		Buzzer_AsyncBeepMult(1, 500, 0);
	}
	else
	if((signalState & Bit(Sig_BUZ)) || (signalState & Bit(Sig_TAMP))){
		Buzzer_Off();
	}
	
	if(sig & Bit(Sig_WG)){
		Env_SetWG26();
	}
	else
	if(signalState & Bit(Sig_WG)){
		Env_Init();
	}
	
	signalState = sig;
	return sig & ~ Bit(Sig_WG);
}

int SignalService_IsTamp(void){
	return (signalState & Bit(Sig_TAMP)) != 0;
}

int SignalService_WG26(void){
	return (signalState & Bit(Sig_WG)) != 0;
}

